
/**
 * Created with IntelliJ IDEA.
 * Description:
 * User: fzykd
 * Date: 2023-04-16
 * Time: 16:58
 */

public class Test {
    public static void main(String[] args) {
        String str = "hello world";


        String s = "hELlo ";
        //1.替换指定字符
        System.out.println(s.replace("he","pj")); //pjllo
        //2.切割
        System.out.println(s.split("hE"));
        //3.字串 获取字符串中的一部分
        System.out.println(str.substring(5)); //一直到结尾  world
        System.out.println(str.substring(0,3)); //前闭后开 hel
        //将字符串大小写转换
        System.out.println(s.toUpperCase()); //大写 HELLO
        System.out.println(s.toLowerCase()); //小写
        //去除字符串两端的空格
        System.out.println(s.trim());

        //将字符数组 转换成字符串
        String myString = "hello123"; //创建的字符串
        char[] myChar = null; //创建的字符数组
        //将字符串转变为字符数组
        myChar = myString.toCharArray();
        for (char o :myChar) {
            System.out.println(o);
        }

        //将字符数组 转为字符串 直接在构造函数中传递字符数组 (1,5)参数可以省略
        String s1 = new String(myChar,1,5); //ello1
        System.out.println(s1);
        String s2 = String.valueOf(myChar,1,5);
        System.out.println(s2);
        System.out.println(s1 == s2); // false 比较的地址 因为不同的对象 地址不同
        System.out.println(s1.equals(s2)); //true
        String s3 = String.copyValueOf(myChar);
        System.out.println(s3);
        System.out.println(myChar);

        //将字符串 转为 字符数组
        byte[] bytes = myString.getBytes();
        for (byte b :bytes) {
            System.out.println(b);
        }


    }
}
